/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 02-mar-2010, 0:11:43
 */

package Presentacion;

import herramientas.Agente_Properties;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;

/**
 *
 * @author tpaxle
 */
public class Principal extends javax.swing.JFrame {

    /** Creates new form Principal */
    public Principal() {
        try {
            initComponents();

            agente_prop = Agente_Properties.getAgenteProperties();
            rutapath_ServidorA= agente_prop.getProperty("opcion.classpath_ServidorA");
            rutalibpath_Cliente=agente_prop.getProperty("opcion.libpath_Cliente");
            rutalibpath_ServidorA= agente_prop.getProperty("opcion.libpath_ServidorA");
            rutapath_Cliente= agente_prop.getProperty("opcion.classpath_Cliente");
            jTextField1.setText(rutapath_ServidorA);
            jTextField2.setText(rutalibpath_Cliente);
            jTextField3.setText(rutapath_Cliente);
            jTextField4.setText(rutalibpath_ServidorA);

        } catch (FileNotFoundException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Autocompilador v0.3.1", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36));
        jLabel1.setText("Autocompilador RMI ");

        jLabel2.setText("by Xule");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(70, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(51, 51, 51))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(62, 62, 62))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "RMI cliente-ServidorA"));

        jLabel3.setText("ClassPath_Servidor");

        jTextField1.setEditable(false);

        jButton1.setText("...");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jLabel4.setText("libCliente_path");

        jTextField2.setEditable(false);

        jButton2.setText("...");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jButton3.setText("run RMIC");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        jButton4.setText("Sincronizacion Libs");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(31, 31, 31)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton2, 0, 0, Short.MAX_VALUE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE))
                .addGap(12, 12, 12))
        );

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "RMI ServidorA-Cliente"));

        jLabel5.setText("ClassPath_Cliente");

        jTextField3.setEditable(false);

        jButton6.setText("...");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton6MouseClicked(evt);
            }
        });

        jLabel6.setText("libServidor_path");

        jTextField4.setEditable(false);

        jButton7.setText("...");
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton7MouseClicked(evt);
            }
        });

        jButton8.setText("run RMIC");
        jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton8MouseClicked(evt);
            }
        });

        jButton9.setText("Sincronizacion Libs");
        jButton9.setEnabled(false);
        jButton9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton9MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addGap(31, 31, 31)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton7, 0, 0, Short.MAX_VALUE)
                            .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 32, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE))
                .addGap(12, 12, 12))
        );

        jButton5.setText("Exit");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(175, 175, 175)
                .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                .addGap(198, 198, 198))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)
                .addGap(22, 22, 22)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        JFileChooser chooser= new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setVisible(true);
        if(chooser.showOpenDialog(null)== JFileChooser.APPROVE_OPTION){
            rutapath_ServidorA= chooser.getSelectedFile().getAbsolutePath()+ "\\";
            System.out.println("Ruta seleccionada: "+ rutapath_ServidorA);
            jTextField1.setText(rutapath_ServidorA);
        }

    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        // TODO add your handling code here:
        JFileChooser chooser= new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setVisible(true);
        if(chooser.showOpenDialog(null)== JFileChooser.APPROVE_OPTION){
            rutalibpath_Cliente= chooser.getSelectedFile().getAbsolutePath()+ "\\";
            System.out.println("Ruta seleccionada: "+ rutalibpath_Cliente);
            jTextField2.setText(rutalibpath_Cliente);
        }
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        
        if(!rutalibpath_Cliente.equals("C:\\") && !rutapath_ServidorA.equals("C:\\")){

            //Ejecucion RMIC
            try
                {
                // Se lanza el ejecutable.
                Process p=Runtime.getRuntime().exec ("cmd /c rmic -d "+ rutapath_ServidorA+ " -classpath "+rutapath_ServidorA + ";"+rutapath_ServidorA + "..\\..\\libs\\ClienteStub.jar;"+ " server.comunicacion.ServidorA");

                // Se obtiene el stream de salida del programa
                InputStream is = p.getInputStream();

                /* Se prepara un bufferedReader para poder leer la salida más comodamente. */
                BufferedReader br = new BufferedReader (new InputStreamReader (is));

                // Se lee la primera linea
                String aux = br.readLine();

                
                jTextArea1.setText(jTextArea1.getText()+ "\n" + "> rmic -d "+ rutapath_ServidorA+ " -classpath "+rutapath_ServidorA + ";"+rutapath_ServidorA + "..\\..\\libs\\ClienteStub.jar;"+ " server.comunicacion.ServidorA ==> Exito");
                // Mientras se haya leido alguna linea

                while (aux!=null)
                {
                    jTextArea1.setText(jTextArea1.getText()+ "\n>> " + aux);
                    // y se lee la siguiente.
                    aux = br.readLine();
                }
            }
            catch (Exception e)
            {
                // Excepciones si hay algún problema al arrancar el ejecutable o al leer su salida.*/
                e.printStackTrace();
            }
            
//Ejecucion jar -cf
             try
                {
                // Se lanza el ejecutable.
                Process p=Runtime.getRuntime().exec ("cmd /c jar -cvf " + rutalibpath_Cliente +  "ServidorAStub.jar -C " + rutapath_ServidorA + " server\\comunicacion\\ServidorA_Stub.class -C "+ rutapath_ServidorA + " server\\comunicacion\\IServidorA.class");

                // Se obtiene el stream de salida del programa
                InputStream is = p.getInputStream();

                /* Se prepara un bufferedReader para poder leer la salida más comodamente. */
                BufferedReader br = new BufferedReader (new InputStreamReader (is));

                // Se lee la primera linea
                String aux = br.readLine();

                
                jTextArea1.setText(jTextArea1.getText()+ "\n" + ">  jar -cf " + rutalibpath_Cliente +  "ServidorBStub.jar \n>> -C " + rutapath_ServidorA + "server\\comunicacion\\ServidorB_Stub.class \n>> -C"+ rutapath_ServidorA + "server\\comunicacion\\IServidorB.class  ==> Exito");
                // Mientras se haya leido alguna linea
                while (aux!=null)
                {
                    jTextArea1.setText(jTextArea1.getText()+ "\n>> " + aux);
                    // y se lee la siguiente.
                    aux = br.readLine();
                }
            }
            catch (Exception e)
            {
                // Excepciones si hay algún problema al arrancar el ejecutable o al leer su salida.*/
                e.printStackTrace();
            }

        }else
            jTextArea1.setText(jTextArea1.getText()+ "\n" + "Falta por introducir el classpath y//o pathlibC");
    }//GEN-LAST:event_jButton3MouseClicked

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton5MouseClicked

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked
        // TODO add your handling code here:
        if(!rutalibpath_Cliente.equals("C:\\") && !rutapath_ServidorA.equals("C:\\")){
            //Ejecucion jar -cf
             try
                {
                // Se lanza el ejecutable.
                Process p=Runtime.getRuntime().exec ("cmd /c jar -cvf " + rutalibpath_Cliente +  "clases.jar -C " + rutapath_ServidorA + " server\\dominio -C "+ rutapath_ServidorA + " server\\excepciones");

                // Se obtiene el stream de salida del programa
                InputStream is = p.getInputStream();

                /* Se prepara un bufferedReader para poder leer la salida más comodamente. */
                BufferedReader br = new BufferedReader (new InputStreamReader (is));

                // Se lee la primera linea
                String aux = br.readLine();

                
                jTextArea1.setText(jTextArea1.getText() + "\n" + ">  jar -cvf " + rutalibpath_Cliente +  "clases.jar \n>> -C " + rutapath_ServidorA + "Dominio\\*.class \n>>-C "+ rutapath_ServidorA + "excepciones\\*.class  ==> Exito");
                // Mientras se haya leido alguna linea
                while (aux!=null)
                {
                    jTextArea1.setText(jTextArea1.getText()+ "\n>>" + aux);
                    // y se lee la siguiente.
                    aux = br.readLine();
                }
            }
            catch (Exception e)
            {
                // Excepciones si hay algún problema al arrancar el ejecutable o al leer su salida.*/
                e.printStackTrace();
            }


        }else
            jTextArea1.setText(jTextArea1.getText()+ "\n" + "Falta por introducir el classpath y//o pathlibC");
    }//GEN-LAST:event_jButton4MouseClicked

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        this.save();
    }//GEN-LAST:event_formWindowClosed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        this.save();
    }//GEN-LAST:event_formWindowClosing

    private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton6MouseClicked
        // TODO add your handling code here:
        JFileChooser chooser= new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setVisible(true);
        if(chooser.showOpenDialog(null)== JFileChooser.APPROVE_OPTION){
            rutapath_Cliente= chooser.getSelectedFile().getAbsolutePath()+ "\\";
            System.out.println("Ruta seleccionada: "+ rutapath_Cliente);
            jTextField3.setText(rutapath_Cliente);
        }

    }//GEN-LAST:event_jButton6MouseClicked

    private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton7MouseClicked
        // TODO add your handling code here:
        // TODO add your handling code here:
        JFileChooser chooser= new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setVisible(true);
        if(chooser.showOpenDialog(null)== JFileChooser.APPROVE_OPTION){
            rutalibpath_ServidorA= chooser.getSelectedFile().getAbsolutePath()+ "\\";
            System.out.println("Ruta seleccionada: "+ rutalibpath_ServidorA);
            jTextField4.setText(rutalibpath_ServidorA);
        }
    }//GEN-LAST:event_jButton7MouseClicked

    private void jButton8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton8MouseClicked
        // TODO add your handling code here:
        if(!rutalibpath_ServidorA.equals("C:\\") && !rutapath_Cliente.equals("C:\\")){

            //Ejecucion RMIC
            try
                {
                // Se lanza el ejecutable.
                Process p=Runtime.getRuntime().exec ("cmd /c rmic -d "+ rutapath_Cliente+ " -classpath "+rutapath_Cliente + ";. cliente.comunicacion.Cliente");

                // Se obtiene el stream de salida del programa
                InputStream is = p.getInputStream();

                /* Se prepara un bufferedReader para poder leer la salida más comodamente. */
                BufferedReader br = new BufferedReader (new InputStreamReader (is));

                // Se lee la primera linea
                String aux = br.readLine();


                jTextArea1.setText(jTextArea1.getText()+ "\n" + "> rmic -classpath "+rutapath_Cliente + ";. cliente.comunicacion.Cliente ==> Exito");
                // Mientras se haya leido alguna linea

                while (aux!=null)
                {
                    jTextArea1.setText(jTextArea1.getText()+ "\n>> " + aux);
                    // y se lee la siguiente.
                    aux = br.readLine();
                }
            }
            catch (Exception e)
            {
                // Excepciones si hay algún problema al arrancar el ejecutable o al leer su salida.*/
                e.printStackTrace();
            }

//Ejecucion jar -cf
             try
                {
                // Se lanza el ejecutable.
                Process p=Runtime.getRuntime().exec ("cmd /c jar -cvf " + rutalibpath_ServidorA +  "ClienteStub.jar -C " + rutapath_Cliente + " cliente\\comunicacion\\Cliente_Stub.class -C "+ rutapath_Cliente + " cliente\\comunicacion\\ICliente.class");

                // Se obtiene el stream de salida del programa
                InputStream is = p.getInputStream();

                /* Se prepara un bufferedReader para poder leer la salida más comodamente. */
                BufferedReader br = new BufferedReader (new InputStreamReader (is));

                // Se lee la primera linea
                String aux = br.readLine();


                jTextArea1.setText(jTextArea1.getText()+ "\n" + ">  jar -cf " + rutalibpath_ServidorA +  "ClienteStub.jar \n>> -C " + rutapath_Cliente + "cliente\\comunicacion\\Cliente_Stub.class \n>> -C"+ rutapath_ServidorA + "cliente\\comunicacion\\ICliente.class  ==> Exito");
                // Mientras se haya leido alguna linea
                while (aux!=null)
                {
                    jTextArea1.setText(jTextArea1.getText()+ "\n>> " + aux);
                    // y se lee la siguiente.
                    aux = br.readLine();
                }
            }
            catch (Exception e)
            {
                // Excepciones si hay algún problema al arrancar el ejecutable o al leer su salida.*/
                e.printStackTrace();
            }

        }else
            jTextArea1.setText(jTextArea1.getText()+ "\n" + "Falta por introducir el classpath y//o pathlibC");

    }//GEN-LAST:event_jButton8MouseClicked

    private void jButton9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton9MouseClicked
        // TODO add your handling code here:
        if(!rutalibpath_ServidorA.equals("C:\\") && !rutapath_Cliente.equals("C:\\")){
            //Ejecucion jar -cf
             try
                {
                // Se lanza el ejecutable.
                Process p=Runtime.getRuntime().exec ("cmd /c jar -cvf " + rutalibpath_ServidorA +  "clases.jar -C " + rutapath_Cliente + " cliente\\dominio -C "+ rutapath_ServidorA + " server\\excepciones");

                // Se obtiene el stream de salida del programa
                InputStream is = p.getInputStream();

                /* Se prepara un bufferedReader para poder leer la salida más comodamente. */
                BufferedReader br = new BufferedReader (new InputStreamReader (is));

                // Se lee la primera linea
                String aux = br.readLine();


                jTextArea1.setText(jTextArea1.getText() + "\n" + ">  jar -cvf " + rutalibpath_Cliente +  "clases.jar \n>> -C " + rutapath_ServidorA + "Dominio\\*.class \n>>-C "+ rutapath_ServidorA + "excepciones\\*.class  ==> Exito");
                // Mientras se haya leido alguna linea
                while (aux!=null)
                {
                    jTextArea1.setText(jTextArea1.getText()+ "\n>>" + aux);
                    // y se lee la siguiente.
                    aux = br.readLine();
                }
            }
            catch (Exception e)
            {
                // Excepciones si hay algún problema al arrancar el ejecutable o al leer su salida.*/
                e.printStackTrace();
            }


        }else
            jTextArea1.setText(jTextArea1.getText()+ "\n" + "Falta por introducir el classpath y//o pathlibC");
    }//GEN-LAST:event_jButton9MouseClicked


    private void save(){
        try {
            this.agente_prop.setProperty("opcion.classpath_ServidorA", jTextField1.getText());
            this.agente_prop.setProperty("opcion.libpath_Cliente", jTextField2.getText());
            this.agente_prop.setProperty("opcion.classpath_Cliente", jTextField3.getText());
            this.agente_prop.setProperty("opcion.libpath_ServidorA", jTextField4.getText());
            this.agente_prop.guardar();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    // End of variables declaration//GEN-END:variables

    private String rutapath_ServidorA = null;
    private String rutalibpath_Cliente= null;
    private String rutapath_Cliente = null;
    private String rutalibpath_ServidorA= null;
    private Agente_Properties agente_prop;
}
